var getData_admin = function () {

    load(".editSelf", 1500);
    $.ajax({
        type: "POST",
        url: "/user/detail?token=" + localStorage['token'],
        data: {
            "id": localStorage['id']
        },
        success: function (data) {
            console.log(data);
            if (data.code == 200) {
                $(".SHinput").children("#name").val(data.data.name);
                $(".SHinput").children("#phone").val(data.data.phone);
                $(".SHinput").children("#email").val(data.data.email);
                $(".SHinput").children("#qq").val(data.data.qq);
                $(".SHinput").children("#id").val(data.data.id);
            } else {
                message("请求失败", "请重新尝试", "error", 500);
            }
        }
    })
};

$("#phone").blur(function () {
    var test = /^1[34578]\d{9}$/;
    var phone = $(this).val();
    if (!test.test(phone)) {
        $(this).parent().children(".errorMsg").text("请输入正确的手机号");
    } else {
        $(this).parent().children(".errorMsg").empty();
    }
    if (phone == "") {
        $(this).parent().children(".errorMsg").text("手机号不能为空");
    }
});

$("#email").blur(function () {
    var test = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
    var email = $(this).val();
    if (!test.test(email)) {
        $(this).parent().children(".errorMsg").text("请输入正确的邮箱");
    } else {
        $(this).parent().children(".errorMsg").empty();
    }
    if (email == "") {
        $(this).parent().children(".errorMsg").text("邮箱不能为空");
    }
});

$("#phone, #email").blur(function () {
    if ($("#phone").parent().children(".errorMsg").text() != "" || $("#email").parent().children(".errorMsg").text() != "") {
        $("#changeSelf_admin").attr("disabled", "disabled");
        $("#changeSelf_admin").addClass("button_cannot");
    } else {
        $("#changeSelf_admin").removeAttr("disabled");
        $("#changeSelf_admin").removeClass("button_cannot");
    }
});


$("#changeSelf_admin").click(function () {
    var phone = $("#phone").val();
    var id = $("#id").val();
    var email = $("#email").val();
    var qq = $("#qq").val();
    swal("确定要修改吗?")
        .then((value) => {
        $.ajax({
            type: "post",
            url: "/user/info/update",
            data: {
                "phone": phone,
                "email": email,
                "id": id,
                "qq": qq,
                "token": localStorage['token']
            },
            success: function (data) {
                console.log(data);
                if (data.code == 200) {
                    load(".editSelf", 1000);
                    setTimeout(function () {
                        message("修改资料成功", "", "success", 2000);
                        // getData_admin();
                    }, 1300);

                } else {
                    message(data.msg, "请重新尝试", "error", 2000);
                }
            }
        })
    }
)
    ;

});

$(window).resize(function () {
    $(".editSelf").children(".content").width($("#body").width() - 200);
});